
  @content = ""
  @url = ""
  @cachedURL = ""
  @title = ""
	@only_text = "&gl=it&strip=1"
	@@count = 0
  
=begin
	url: webpage url
	cachedURL: cached webpage url
	title: webpage title
	index: first block word index
=end
  def initialize(url, cachedURL, title, page)
    @url = url
    @cachedURL = cachedURL
    @title = title
		# @@count: number of ResultPage object
		@@count = @@count+1
		# integers indexes list (M elements). Each index points to the begin of the word block
		# One for every ResultPage
		@indexTable = Array.new(M) {Array.new}
		# download the result
		self.download_page
  end

	# test method
	def to_s
		return "Title : #{@title}"
	end 
	
	def download_page
		if (@cachedURL.kind_of?(URI::HTTP))
			# puts @cachedURL.inspect
			# only_text page version
			@cachedURL.query += "&gl=it&strip=1"
			
=begin
			#-> old code
			doc = Hpricot(open(@cachedURL))
			textdoc = doc.at('body')
			file = File.new("./tmp/#{@@count} - #{@title[0,5]}", "w")
			if (textdoc != nil)
				@content = textdoc.to_plain_text.split(/\W+/u)
				#puts @content
			end
			# -> end old code
=end

		#-> new code
		textdoc = htmlfile2text(@cachedURL)
		# -> end new code

		file = File.new("./tmp/#{@@count}-#{@title[0,10]}", "w")
		file.puts textdoc
		file.close
		# 	@content = textdoc.split(/\W+/)
		puts "--- @content ---"
		#puts @content
		if (@content != nil)		
				#puts "=== blockHash ResultPage==="
				i = 0
				j = BLOCK_SIZE-1
				while i < @content.length-1
					# i is the index of the first word 
					blockhash(@content[i..j], i)
					i = j+1
					j = j+BLOCK_SIZE
				end # while
				#puts "=== blockHash ResultPage end ==="	
		end # @content if
	end # @cachedURL if
end # method 
	
	#private method of the class
  private
  def blockhash(a, pos)
     hasharray = Array.new(0)
     sum = 0
     i = 0	
     for x in a
        hasharray << x.hash * P**i
        i = i+1
     end
     hasharray.each {|elem| sum = sum + elem}
     @indexTable[sum % M] << pos # posizione della prima parola con un dato hash
  end
	
=begin
	find block that match an input text block
=end	
	def similarity()
	
	end
